Trò chơi đua xe động vật trong UNITY Engine
114.942 lượt xem;
- Pagination.cs
- MapScreen /
- AnimalRacing /
- Scripts /
- Assets /
- project /
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4
5 public class Pagination : MonoBehaviour {
6 [SerializeField]
7 Transform[] pages;
8 [SerializeField]
9 Transform selection;
10
11 int currentPage;
12 private void Update()
13 {
14 if (Vector3.Distance(selection.position, GetCurrentTransform().position) > 0.1f)
15 {
16 selection.position = Vector3.Lerp(selection.position, GetCurrentTransform().position, Time.deltaTime * 1000);
17 }
18 }
19
20 public void Set(int page)
21 {
22 currentPage = page;
23 }
24
25 Transform GetCurrentTransform()
26 {
27 return pages[Mathf.Clamp(currentPage, 0, pages.Length)];
28 }
29 }
2 using System.Collections.Generic;
3 using UnityEngine;
4
5 public class Pagination : MonoBehaviour {
6 [SerializeField]
7 Transform[] pages;
8 [SerializeField]
9 Transform selection;
10
11 int currentPage;
12 private void Update()
13 {
14 if (Vector3.Distance(selection.position, GetCurrentTransform().position) > 0.1f)
15 {
16 selection.position = Vector3.Lerp(selection.position, GetCurrentTransform().position, Time.deltaTime * 1000);
17 }
18 }
19
20 public void Set(int page)
21 {
22 currentPage = page;
23 }
24
25 Transform GetCurrentTransform()
26 {
27 return pages[Mathf.Clamp(currentPage, 0, pages.Length)];
28 }
29 }